﻿CREATE TABLE [dbo].[tbDislocation] (
    [id]                      INT           IDENTITY (1, 1) NOT NULL,
    [InventoryCarriageNumber] NVARCHAR (8)  NULL,
    [WeightTons]              NVARCHAR (3)  NULL,
    [DestinationStation_Code]   NVARCHAR (7)           NOT NULL,
    [CargoCodeTariff_ShortCode]      CHAR (5)           NOT NULL,
    [ConsigneeCode]        NVARCHAR (4)           NOT NULL,
    [ParkType]                NVARCHAR (2)  NULL,
    [StartStation_Code]         NVARCHAR (7)           NOT NULL,
    [OperationCode_Code]        CHAR (2)         NOT NULL,
    [OperationDate]           NVARCHAR (4)  NULL,
    [OperationYear]           NVARCHAR (2)  NULL,
    [OperationTime]           NVARCHAR (4)  NULL,
    [StationOfOperation_Code]   NVARCHAR (7)           NOT NULL,
    [DeliveryRoad_Code]         NVARCHAR (50)           NOT NULL,
    [ReceiptRoad_Code]          NVARCHAR (50)           NOT NULL,
    [TrainIndex]              NVARCHAR (13) NULL,
    [TrainNumber]             NVARCHAR (4)  NULL,
	[OperationType_Code] TiNYINT null,
    FOREIGN KEY ([DestinationStation_Code]) REFERENCES [dbo].[Station] ([Code]),
    FOREIGN KEY ([CargoCodeTariff_ShortCode]) REFERENCES [dbo].[Cargo] ([ShortCode]),
    FOREIGN KEY ([StartStation_Code]) REFERENCES [dbo].[Station] ([Code]),
    FOREIGN KEY ([OperationType_Code],[OperationCode_Code]) REFERENCES [dbo].[CarOperation] ([OperationType],[Code]),
    FOREIGN KEY ([StationOfOperation_Code]) REFERENCES [dbo].[Station] ([Code]),
    FOREIGN KEY ([DeliveryRoad_Code]) REFERENCES [dbo].[Road] ([Code]),
    FOREIGN KEY ([ReceiptRoad_Code]) REFERENCES [dbo].[Road] ([Code])
);
